# 字符型不可以转换为逻辑与数值

# for(i in c(1:10)){
#   if(i%%2==0){
#     cat("偶数:",i,"\n")
#   }
#   else{
#     cat("奇数:",i,"\n")
#   }
# }



# add2nfunc<-function(a,b){
#   x=1;
#   x=2;
#   return (a+b);
# }
#
# print(ret <- add2nfunc(1,2))

mydata<-matrix(c(1,2,3,4,5,6),nrow=2,ncol=3)

mydata3<-matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,dimnames = list(c("r1","r2"),c("c1","c2","c3")))

#matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE,dimnames = NULL);
# 其中data表示要处理的数据（向量)，
# nrow表示行，ncol表示列，byrow表示是否按行排列，
# 默认是列排，dimnames表示行与列的名字，默认是没有，要使用列表设置。

# mydata1<-matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,byrow=T)
#
# mydata4 <- rbind(c(1,2,3),c(4,5,6))
#
# mydata5 <- cbind(c(1,2,3),c(4,5,6))
#
# a<-c(1,2,3,4,5,6)
#
# mydata7<-cbind(c(1,2,3,4,5),c(4,5))
#
# mydata8<-cbind(c(1,2),c(4,5,6,7,8))
#
# mydata10<-matrix(c(2,5,FALSE,TRUE),2,2)
#
# mydata9<-matrix(c(1,3,FALSE,TRUE,"ABC","babiQ"),2,3)
#
# mymatrix<-matrix(c(1:25),5,5)
#
#
# fa<-matrix(c(2,3,4,5),2,2,dimnames =list(c("第一行","第二行"),c("第一列","第二列")))

mymatrix<-matrix(c(1:25),5,5)

mymatrix_rowmean<-apply(mymatrix,1,mean)
mymatrix_colmean<-apply(mymatrix,2,mean)

mymatrix_rowmean1<-matrix(mymatrix_rowmean,length(mymatrix_rowmean),1)  #转换为一列的矩阵

mymatrix_colmean1<-matrix(mymatrix_colmean,1,length(mymatrix_colmean))  #转换为一行的矩阵

mymatrix_colmean1[6]<-NA

mymatrix2<-cbind(mymatrix,mymatrix_rowmean1)    #按列把两个矩阵接起来

mymatrix3<-rbind(mymatrix2,mymatrix_colmean1)	  #按列把两个矩阵接起来


a<-c("r1","r2","r3","r4","r5","列均值")
b<-c("c1","c2","c3","c4","c5","行均值")

dimnames(mymatrix3)<-list(a,b)

class(mymatrix)


attributes(mydata)

ret <- 3
attributes(add2nfunc(1,2))

attributes(ret)

